package ui;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import Work.Jdbc;
/*查询选项四个查询按钮*/
public class RecordSearchButtons extends JFrame implements ActionListener {
	private JButton searchall;
	private JButton searchb_id;
	private JButton searchr_id;
	private JButton searchl_id;
	private JButton searchbor_time;
	private JButton searchret_time;
	private JButton returnbutton;
	//创建数据库连接类对象

    Jdbc db = new Jdbc();
	public RecordSearchButtons() {
		JFrame jFrame = new JFrame("借阅记录查询功能选择");
		jFrame.setLayout(new BorderLayout());
		JPanel jp1 = new JPanel(new GridLayout(3, 2, 10, 5));//设置新面板
		// 网格布局GridLayout(int rows, int columns, int hgap, int vgap)行数，列数，组件水平间距，垂直间距
		jp1.setBorder(BorderFactory.createTitledBorder("借阅记录查询"));
		//this.setLayout(new FlowLayout());
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("借阅记录查询系统");
		setSize(300, 250);
		setLocationRelativeTo(null);
		

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		searchall = new JButton("查询全部借阅记录");
		searchb_id = new JButton("按书籍编号查询");
		searchr_id = new JButton("按读者编号查询");
		searchl_id = new JButton("按管理员编号查询");
		searchbor_time = new JButton("按借阅时间查询");
		searchret_time = new JButton("按归还时间查询");
		
		jp1.add(searchall);
		jp1.add(searchb_id);
		jp1.add(searchr_id);
		jp1.add(searchl_id);
		jp1.add(searchbor_time);
		jp1.add(searchret_time);
		returnbutton = new JButton("返回");
		returnbutton.addActionListener(this);
		JPanel jp2 = new JPanel();
		jp2.add(returnbutton);
		add(jp2, BorderLayout.SOUTH);// 把按钮放到窗口最下方
		getContentPane().add(jp1,BorderLayout.CENTER);

		searchall.addActionListener(this);
		searchb_id.addActionListener(this);
		searchr_id.addActionListener(this);
		searchl_id.addActionListener(this);
		searchbor_time.addActionListener(this);
		searchret_time.addActionListener(this);

		this.setVisible(true);
		
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		RecordSearch1 RecordSearch1 = new RecordSearch1();
		if (e.getSource() == searchall) {
			this.dispose();
			RecordSearch1.SearchAll(db);
		}else if (e.getSource() == searchr_id) {
			this.dispose();
			RecordSearch1.Searchr_idbutton();
		}else if (e.getSource() == searchb_id) {
			this.dispose();
			RecordSearch1.Searchb_idbutton();
		}else if (e.getSource() == searchl_id) {
			this.dispose();
			RecordSearch1.Searchl_idbutton();
		}else if (e.getSource() == searchbor_time) {
			this.dispose();
			RecordSearch1.Searchbor_timebutton();
		}else if (e.getSource() == searchret_time) {
			this.dispose();
			RecordSearch1.Searchret_timebutton();
		} else if (e.getSource() == returnbutton) {
			this.dispose();
			new LibrarianOp();
		}  
	}
}
